package ylyhappy.cn.ideavim.lg.db

import android.content.ContentValues
import android.database.sqlite.SQLiteDatabase

data class LineData(val map:String, val actionpre: String?, val action_en: String, val action_zh: String,
    val shortcut: String, val actionafter: String,val cr: String?){
    override fun toString(): String {
        return "#${action_zh.toString()} \n $map $actionpre $action_en $actionafter $shortcut $cr "
    }
}

fun createLine(db: SQLiteDatabase, map: String, actionpre: String?, actionId: Int, shortcut: String, actionafter: String?, cr: String?): Long {
    val values = ContentValues().apply {
        put("map", map)
        put("action_id", actionId)
        put("shortcut", shortcut)
        if (actionpre != null){
            put("actionpre", actionpre)
        }
        if (actionafter != null){
            put("actionafter", actionafter)
        }
        if (cr != null){
            put("cr", cr)
        }
    }
    return db.insert("Line", null, values)
}

fun initLine(db: SQLiteDatabase){
    // map ' ' action ' ' <C-v> <CR>
    // map ' ' action ' ' <C-a> <CR>
    // map ' ' action ' ' <C-b> <CR>
    // map ' ' action ' ' <C-h> <CR>
    createLine(db,"map", "", 10, "<C-v>", " ","<CR>");
    createLine(db,"map", "", 15, "<C-v>", " ","<CR>");
    createLine(db,"map", "", 20, "<C-v>", " ","<CR>");
    createLine(db,"map", "", 30, "<C-v>", " ","<CR>");
    createLine(db,"map", "", 40, "<C-v>", " ","<CR>");

}